package patterns;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class SubjectImplToo implements Subject {

	private List observers = new ArrayList();
	private String state = null;

	@Override
	public void addObserver(Observer o) {
		observers.add(o);

	}

	private void notifyObservers() {
		Iterator i = observers.iterator();
		while (i.hasNext()) {
			Observer o = (Observer) i.next();
			o.update(this);
		}
	}

	@Override
	public void removeObserver(Observer o) {
		observers.remove(o);
	}

	@Override
	public String getState() {
		return state;
	}

	@Override
	public void setState(String state) {
		this.state = state;
		notifyObservers();
	}

}
